home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / blueprnt.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  198 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *blueprnt_scrollram;
  14.  
  15. static int gfx_bank,flipscreen;
  16.  
  17.  
  18.  
  19. /***************************************************************************
  20.  
  21.   Convert the color PROMs into a more useable format.
  22.  
  23.   Blue Print doesn't have color PROMs. For sprites, the ROM data is directly
  24.   converted into colors; for characters, it is converted through the color
  25.   code (bits 0-2 = RBG for 01 pixels, bits 3-5 = RBG for 10 pixels, 00 pixels
  26.   always black, 11 pixels use the OR of bits 0-2 and 3-5. Bit 6 is intensity
  27.   control)
  28.  
  29. ***************************************************************************/
  30.  
  31. void blueprnt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  32. {
  33.     int i;
  34.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  35.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  36.  
  37.  
  38.     for (i = 0;i < 16;i++)
  39.     {
  40.         (*palette++) = ((i >> 0) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  41.         (*palette++) = ((i >> 2) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  42.         (*palette++) = ((i >> 1) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  43.     }
  44.  
  45.  
  46.     /* chars */
  47.     for (i = 0;i < 128;i++)
  48.     {
  49.         int base =  (i & 0x40) ? 8 : 0;
  50.         COLOR(0,4*i+0) = base + 0;
  51.         COLOR(0,4*i+1) = base + ((i >> 0) & 7);
  52.         COLOR(0,4*i+2) = base + ((i >> 3) & 7);
  53.         COLOR(0,4*i+3) = base + (((i >> 0) & 7) | ((i >> 3) & 7));
  54.     }
  55.  
  56.     /* sprites */
  57.     for (i = 0;i < 8;i++)
  58.         COLOR(1,i) = i;
  59. }
  60.  
  61.  
  62.  
  63. WRITE_HANDLER( blueprnt_flipscreen_w )
  64. {
  65.     if (flipscreen != (~data & 2))
  66.     {
  67.         flipscreen = ~data & 2;
  68.         memset(dirtybuffer,1,videoram_size);
  69.     }
  70.  
  71.     if (gfx_bank != ((data & 4) >> 2))
  72.     {
  73.         gfx_bank = ((data & 4) >> 2);
  74.         memset(dirtybuffer,1,videoram_size);
  75.     }
  76. }
  77.  
  78.  
  79.  
  80. /***************************************************************************
  81.  
  82.   Draw the game screen in the given osd_bitmap.
  83.   Do NOT call osd_update_display() from this function, it will be called by
  84.   the main emulation engine.
  85.  
  86. ***************************************************************************/
  87. void blueprnt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  88. {
  89.     int offs;
  90.     int scroll[32];
  91.  
  92.  
  93.     /* for every character in the Video RAM, check if it has been modified */
  94.     /* since last time and update it accordingly. */
  95.     for (offs = videoram_size - 1;offs >= 0;offs--)
  96.     {
  97.         if (dirtybuffer[offs])
  98.         {
  99.             int sx,sy;
  100.  
  101.  
  102.             dirtybuffer[offs] = 0;
  103.  
  104.             sx = 31 - offs / 32;
  105.             sy = offs % 32;
  106.             if (flipscreen)
  107.             {
  108.                 sx = 31 - sx;
  109.                 sy = 31 - sy;
  110.             }
  111.  
  112.             drawgfx(tmpbitmap,Machine->gfx[0],
  113.                     videoram[offs] + 256 * gfx_bank,
  114.                     colorram[offs] & 0x7f,
  115.                     flipscreen,flipscreen,
  116.                     8*sx,8*sy,
  117.                     0,TRANSPARENCY_NONE,0);
  118.         }
  119.     }
  120.  
  121.  
  122.     /* copy the temporary bitmap to the screen */
  123.     {
  124.         int i;
  125.  
  126.  
  127.         if (flipscreen)
  128.         {
  129.             for (i = 0;i < 32;i++)
  130.             {
  131.                 scroll[31-i] = blueprnt_scrollram[32-i];    /* mmm... */
  132.             }
  133.         }
  134.         else
  135.         {
  136.             for (i = 0;i < 32;i++)
  137.             {
  138.                 scroll[i] = -blueprnt_scrollram[30-i];    /* mmm... */
  139.             }
  140.         }
  141.  
  142.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  143.     }
  144.  
  145.  
  146.     /* Draw the sprites */
  147.     for (offs = 0;offs < spriteram_size;offs += 4)
  148.     {
  149.         int sx,sy,flipx,flipy;
  150.  
  151.  
  152.         sx = spriteram[offs + 3];
  153.         sy = 240 - spriteram[offs + 0];
  154.         flipx = spriteram[offs + 2] & 0x40;
  155.         flipy = spriteram[offs + 2 - 4] & 0x80;    /* -4? Awkward, isn't it? */
  156.         if (flipscreen)
  157.         {
  158.             sx = 248 - sx;
  159.             sy = 240 - sy;
  160.             flipx = !flipx;
  161.             flipy = !flipy;
  162.         }
  163.  
  164.         drawgfx(bitmap,Machine->gfx[1],
  165.                 spriteram[offs + 1],
  166.                 0,
  167.                 flipx,flipy,
  168.                 2+sx,sy-1,    /* sprites are slightly misplaced, regardless of the screen flip */
  169.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  170.     }
  171.  
  172.  
  173.     /* redraw the characters which have priority over sprites */
  174.     for (offs = videoram_size - 1;offs >= 0;offs--)
  175.     {
  176.         if (colorram[offs] & 0x80)
  177.         {
  178.             int sx,sy;
  179.  
  180.  
  181.             sx = 31 - offs / 32;
  182.             sy = offs % 32;
  183.             if (flipscreen)
  184.             {
  185.                 sx = 31 - sx;
  186.                 sy = 31 - sy;
  187.             }
  188.  
  189.             drawgfx(bitmap,Machine->gfx[0],
  190.                     videoram[offs] + 256 * gfx_bank,
  191.                     colorram[offs] & 0x7f,
  192.                     flipscreen,flipscreen,
  193.                     8*sx,(8*sy+scroll[sx]) & 0xff,
  194.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  195.         }
  196.     }
  197. }
  198.